package com.gt.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gt.admin.domain.QuestionnaireManage;
import com.gt.admin.domain.vo.QuestionnaireManageVO;
import com.gt.admin.mapper.QuestionnaireManageMapper;
import com.gt.admin.service.IQuestionnaireManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 问卷管理service
 */
@Service
public class QuestionnaireManageServiceImpl extends ServiceImpl<QuestionnaireManageMapper, QuestionnaireManage> implements IQuestionnaireManageService {
    @Autowired
    private QuestionnaireManageMapper questionnaireManageMapper;

    @Override
    public List<QuestionnaireManage> getList(QuestionnaireManageVO questionnaireManageVO) {
        if (questionnaireManageVO.getQueStatus() == ""){
            questionnaireManageVO.setQueStatus(null);
        }if (questionnaireManageVO.getAssociation() == ""){
            questionnaireManageVO.setAssociation(null);
        }if (questionnaireManageVO.getName() == ""){
            questionnaireManageVO.setName(null);
        }if (questionnaireManageVO.getSickId() == null){
            questionnaireManageVO.setSickId(0L);
        }LambdaQueryWrapper<QuestionnaireManage> queryWrapper = new LambdaQueryWrapper<>(questionnaireManageVO);
        Date startTime = questionnaireManageVO.getStartTime();
        Date endTime = questionnaireManageVO.getEndTime();
        if(startTime != null){
            queryWrapper.ge(QuestionnaireManage::getCommitTime, startTime);
        }if (endTime != null){
            queryWrapper.le(QuestionnaireManage::getCommitTime, endTime);
        }return list(queryWrapper);
    }

    @Override
    public boolean audit(Long queId, String queStatus) {
        QuestionnaireManage questionnaireManage = new QuestionnaireManage();
        questionnaireManage.setQueId(queId);
        questionnaireManage.setQueStatus(queStatus);
        return questionnaireManageMapper.audit(questionnaireManage);
    }
}
